<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <meta charset="UTF-8">
    <title>Record</title>
    <link href="/layui/css/layui.css" type="text/css" rel="stylesheet">
    <script src="/layui/layui.js"></script>
    <script src="/js/libSys/commonHeader.js" rel="script"></script>
</head>
<body>
<div th:replace="libSys/libSysCommonHeader::libSysCommonHeader"></div>
<div class="layui-container" style="width:88%">

    <table class="layui-table" lay-skin="line" lay-size="lg">
        <colgroup>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>记录号</th>
            <th>册编号</th>
            <th>书名</th>
            <th>用户ID</th>
            <th>用户名</th>
            <th>借阅时间</th>
            <th>当前状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        <tr th:each="oneRecord: ${record}">
            <td th:text="${oneRecord.borrowId}"></td>
            <td th:text="${oneRecord.bookId}"></td>
            <td th:text="${oneRecord.title}"></td>
            <td th:text="${oneRecord.userId}"></td>
            <td th:text="${oneRecord.username}"></td>
            <td th:text="${oneRecord.borrowTime}"></td>
            <td>
                <span th:if="${oneRecord.state} eq '0'">已归还</span>
                <span th:if="${oneRecord.state} ne '0'">未归还</span>
            </td>
            <td>
                <div class="layui-btn-group" th:if="${oneRecord.state} ne '0'" sec:authorize="hasRole('ROLE_ADMIN')">
                    <button type="button" class="layui-btn bookReturnButton" th:attr='return-url=@{/manager/returnBook/}+${oneRecord.bookId}'>还书</button>
                </div>

            </td>
        </tr>

        </tbody>
    </table>

</div>

<script>
    layui.use(["jquery","layer"],function(){
        var $ = layui.jquery;
        var layer = layui.layer;
        $(".bookReturnButton").on("click",function(data){
            var return_url = $(this).attr("return-url");
            $.post({
                url:return_url,
                data:return_url,
                success:function(data){
                    location.reload();
                },
                error:function(data){
                    location.reload();
                }
            });
        });
    })
</script>

</body>
</html>